#include <algorithm>
#include "MacroCommand.h"

struct Executor {
	void operator() (ICommand * cmd) { cmd->Execute(); }
} mExecutor;

struct Undoer {
	void operator() (ICommand * cmd) { cmd->Undo(); }
} mUndoer;

void MacroCommand::AddCommand(ICommand * com) {
	if (com == 0) { throw std::exception("null pointer in MacroCommand()..."); }
	mCommands.push_back(com);
}

void MacroCommand::Execute() {
	std::for_each(mCommands.begin(), mCommands.end(), mExecutor);
}

void MacroCommand::Undo() {
	std::for_each(mCommands.begin(), mCommands.end(), mExecutor);
}